package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86131
 * Date: 2024-02-20
 * Time: 15:44
 */
public class FindOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书");
        System.out.println("请输入要查找图书的书名: ");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currenSize = bookList.getUsedSize(); //得到书架的图书数量
        for (int i = 0; i < currenSize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                System.out.println("存在这本书,信息如下:");
                System.out.println(book); //会直接打印book的所有信息
                return;
            }
        }

        System.out.println("没有找到你要的书,书名为: "+name);
    }
}
